//=======================================================
// 作者：LR
// 公司：广州旗博士科技有限公司
// 描述：工具人
// 创建时间：#CreateTime#
//=======================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Sailfish
{
	public class UIEditor : MonoBehaviour 
	{
 

        public float minAngle = -3.0f;
        public float maxAngle =  3.0f;

        public float minLength = -3.0f;
        public float maxLength = 3.0f;

        public Text angleValue;
        public Text lengthValue;
        public Slider angleSlider;

		public Slider lengthSlider;

        public CameraData data;
        public CameraSetup setup;

        public GameObject plane;

        private void Start()
        {
            var    angleRadio  = Mathf.InverseLerp(minAngle, maxAngle, data.angle);
            var    lengthRadio = Mathf.InverseLerp(minAngle, maxAngle, data.EyeSeparation);

            angleValue.text    =        $"双眼聚焦：{data.angle}"; 
            lengthValue.text   =        $"双眼瞳距：{data.EyeSeparation}"; 

            lengthSlider.value =           lengthRadio;
			 angleSlider.value =           angleRadio;

			angleSlider.onValueChanged.AddListener(SilderAngle);
			lengthSlider.onValueChanged.AddListener(SilderLength);

            if (Application.platform != RuntimePlatform.WindowsEditor)
            {
                plane.gameObject.SetActive(false);
            }
        }

        public void SilderAngle(float value)
        {
            var       angle = Mathf.Lerp(minAngle, maxAngle, value);
            angleValue.text = $"双眼聚焦：{angle}";
            data.angle      =  angle;
            setup.Check();
        }
        public void SilderLength(float value)
        {
            var         length = Mathf.Lerp(minLength, maxLength, value);
            lengthValue.text   = $"双眼瞳距：{length}";  
            data.EyeSeparation = length;
            setup.Check();
        }

        void Update()
        {
            if (Input.GetKeyDown(KeyCode.S))
            {
                var newAction = plane.activeInHierarchy;
				plane.SetActive(!newAction);
            }
        }
    }
}
